<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no"><title>教程 | lovewhoilove 的小站</title><meta name="author" content="lovewhoilove"><meta name="copyright" content="lovewhoilove"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="原文链接及内容原文链接：https:&#x2F;&#x2F;openlayers.org&#x2F;doc&#x2F;tutorials&#x2F; ，这里将三部分内容合并翻译   基本概念MapOpenLayers的核心组件是Map(来自ol&#x2F;Map模块)。它会在一个目标容器中进行渲染(例如，包含地图的Web页面上的div元素)。所有关于的map(对象)的属性可以在构造(实例对象)时配置，也可以使用setter方法，例如setTarget()。">
<meta property="og:type" content="website">
<meta property="og:title" content="教程">
<meta property="og:url" content="https://lovewhoilove.gitee.io/tutorials/">
<meta property="og:site_name" content="lovewhoilove 的小站">
<meta property="og:description" content="原文链接及内容原文链接：https:&#x2F;&#x2F;openlayers.org&#x2F;doc&#x2F;tutorials&#x2F; ，这里将三部分内容合并翻译   基本概念MapOpenLayers的核心组件是Map(来自ol&#x2F;Map模块)。它会在一个目标容器中进行渲染(例如，包含地图的Web页面上的div元素)。所有关于的map(对象)的属性可以在构造(实例对象)时配置，也可以使用setter方法，例如setTarget()。">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://lovewhoilove.gitee.io/img/avatar.png">
<meta property="article:published_time" content="2023-11-29T01:28:05.197Z">
<meta property="article:modified_time" content="2023-11-29T01:28:05.197Z">
<meta property="article:author" content="lovewhoilove">
<meta property="article:tag" content="GIS,前端,Windows">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://lovewhoilove.gitee.io/img/avatar.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="https://lovewhoilove.gitee.io/tutorials/"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="manifest" href="/img/pwa/manifest.json"/><meta name="msapplication-TileColor" content="#49b1f5"/><link rel="apple-touch-icon" sizes="180x180" href="/img/pwa/apple-touch-icon.png"/><link rel="icon" type="image/png" sizes="32x32" href="/img/pwa/32.png"/><link rel="icon" type="image/png" sizes="16x16" href="/img/pwa/16.png"/><link rel="mask-icon" href="/img/pwa/32.png" color="#5bbad5"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = { 
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":false,"languages":{"hits_empty":"找不到您查询的内容：${query}"}},
  translate: undefined,
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '天',
  date_suffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: {"limitCount":50,"languages":{"author":"作者: lovewhoilove","link":"链接: ","source":"来源: lovewhoilove 的小站","info":"著作权归作者所有。商业转载请联系作者获得授权，非商业转载请注明出处。"}},
  lightbox: 'fancybox',
  Snackbar: undefined,
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: true,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: false,
    rightside: true,
  }
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: '教程',
  isPost: false,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-11-29 09:28:05'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          if (t === 'dark') activateDarkMode()
          else if (t === 'light') activateLightMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><link rel="stylesheet" href="/css/progress_bar.css"><link rel="stylesheet" href="/css/custom.css"><svg aria-hidden="true" style="position:absolute; overflow:hidden; width:0; height:0"><symbol id="icon-sun" viewBox="0 0 1024 1024"><path d="M960 512l-128 128v192h-192l-128 128-128-128H192v-192l-128-128 128-128V192h192l128-128 128 128h192v192z" fill="#FFD878" p-id="8420"></path><path d="M736 512a224 224 0 1 0-448 0 224 224 0 1 0 448 0z" fill="#FFE4A9" p-id="8421"></path><path d="M512 109.248L626.752 224H800v173.248L914.752 512 800 626.752V800h-173.248L512 914.752 397.248 800H224v-173.248L109.248 512 224 397.248V224h173.248L512 109.248M512 64l-128 128H192v192l-128 128 128 128v192h192l128 128 128-128h192v-192l128-128-128-128V192h-192l-128-128z" fill="#4D5152" p-id="8422"></path><path d="M512 320c105.888 0 192 86.112 192 192s-86.112 192-192 192-192-86.112-192-192 86.112-192 192-192m0-32a224 224 0 1 0 0 448 224 224 0 0 0 0-448z" fill="#4D5152" p-id="8423"></path></symbol><symbol id="icon-moon" viewBox="0 0 1024 1024"><path d="M611.370667 167.082667a445.013333 445.013333 0 0 1-38.4 161.834666 477.824 477.824 0 0 1-244.736 244.394667 445.141333 445.141333 0 0 1-161.109334 38.058667 85.077333 85.077333 0 0 0-65.066666 135.722666A462.08 462.08 0 1 0 747.093333 102.058667a85.077333 85.077333 0 0 0-135.722666 65.024z" fill="#FFB531" p-id="11345"></path><path d="M329.728 274.133333l35.157333-35.157333a21.333333 21.333333 0 1 0-30.165333-30.165333l-35.157333 35.157333-35.114667-35.157333a21.333333 21.333333 0 0 0-30.165333 30.165333l35.114666 35.157333-35.114666 35.157334a21.333333 21.333333 0 1 0 30.165333 30.165333l35.114667-35.157333 35.157333 35.157333a21.333333 21.333333 0 1 0 30.165333-30.165333z" fill="#030835" p-id="11346"></path></symbol></svg><!-- hexo injector head_end start --><link rel="stylesheet" href="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/animate.min.css" media="print" onload="this.media='screen'"><!-- hexo injector head_end end --><meta name="generator" content="Hexo 5.4.2"></head><body><div id="loading-box" onclick="document.getElementById(&quot;loading-box&quot;).classList.add(&quot;loaded&quot;)"><div class="loading-bg"><div class="loading-img"></div><div class="loading-image-dot"></div></div></div><script>const preloader = {
  endLoading: () => {
    document.body.style.overflow = 'auto';
    document.getElementById('loading-box').classList.add("loaded")
  },
  initLoading: () => {
    document.body.style.overflow = '';
    document.getElementById('loading-box').classList.remove("loaded")

  }
}
window.addEventListener('load',()=> { preloader.endLoading() })

if (true) {
  document.addEventListener('pjax:send', () => { preloader.initLoading() })
  document.addEventListener('pjax:complete', () => { preloader.endLoading() })
}</script><link rel="stylesheet" href="/css/custom.css"/><script src="https://cdn.jsdelivr.net/npm/pace-js/pace.min.js"></script><div id="web_bg"></div><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "/img/friend_404.gif" data-lazy-src="/img/avatar.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">250</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">327</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div><hr/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-newspaper"></i><span> 文章相关</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-timeline"></i><span> 时间轴</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-layer-group"></i><span> Openlayers</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/doc/"><i class="fa-fw fas fa-book-reader"></i><span> 说明文档</span></a></li><li><a class="site-page child" href="/quick-start/"><i class="fa-fw fas fa-bolt"></i><span> 快速入门</span></a></li><li><a class="site-page child" href="/tutorials/"><i class="fa-fw fas fa-book"></i><span> 教程</span></a></li><li><a class="site-page child" href="/faq/"><i class="fa-fw fas fa-question"></i><span> 常见问题</span></a></li><li><a class="site-page child" href="/workshop/"><i class="fa-fw fas fa-graduation-cap"></i><span> 研讨会</span></a></li><li><a class="site-page child" href="/examples/"><i class="fa-fw fas fa-laptop-code"></i><span> 示例</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 网址导航</span></a></div></div></div></div><div class="page" id="body-wrap"><header class="not-home-page" id="page-header" style="background-image: url('/img/homepage-banner.webp')"><nav id="nav"><span id="blog_name"><a id="site-name" href="/">lovewhoilove 的小站</a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-newspaper"></i><span> 文章相关</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/archives/"><i class="fa-fw fas fa-timeline"></i><span> 时间轴</span></a></li><li><a class="site-page child" href="/categories/"><i class="fa-fw fas fa-folder-open"></i><span> 分类</span></a></li><li><a class="site-page child" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></li></ul></div><div class="menus_item"><a class="site-page group" href="javascript:void(0);"><i class="fa-fw fas fa-layer-group"></i><span> Openlayers</span><i class="fas fa-chevron-down"></i></a><ul class="menus_item_child"><li><a class="site-page child" href="/doc/"><i class="fa-fw fas fa-book-reader"></i><span> 说明文档</span></a></li><li><a class="site-page child" href="/quick-start/"><i class="fa-fw fas fa-bolt"></i><span> 快速入门</span></a></li><li><a class="site-page child" href="/tutorials/"><i class="fa-fw fas fa-book"></i><span> 教程</span></a></li><li><a class="site-page child" href="/faq/"><i class="fa-fw fas fa-question"></i><span> 常见问题</span></a></li><li><a class="site-page child" href="/workshop/"><i class="fa-fw fas fa-graduation-cap"></i><span> 研讨会</span></a></li><li><a class="site-page child" href="/examples/"><i class="fa-fw fas fa-laptop-code"></i><span> 示例</span></a></li></ul></div><div class="menus_item"><a class="site-page" href="/link/"><i class="fa-fw fas fa-link"></i><span> 网址导航</span></a></div></div><div id="toggle-menu"><a class="site-page"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="page-site-info"><h1 id="site-title">教程</h1></div></header><main class="layout" id="content-inner"><div id="page"><div id="article-container"><details class="toggle" style="border: 1px solid black"><summary class="toggle-button" style="background-color: black;color: #fff">原文链接及内容</summary><div class="toggle-content"><p>原文链接：<a target="_blank" rel="noopener" href="https://openlayers.org/doc/tutorials/">https://openlayers.org/doc/tutorials/</a> ，这里将三部分内容合并翻译</p>
<iframe src="https://openlayers.org/doc/tutorials/" width="100%" height="400px" frameborder="0" seamless></iframe></div></details>

<h2 id="基本概念"><a href="#基本概念" class="headerlink" title="基本概念"></a>基本概念</h2><h3 id="Map"><a href="#Map" class="headerlink" title="Map"></a>Map</h3><p>OpenLayers的核心组件是<code>Map</code>(来自<code>ol/Map</code>模块)。它会在一个目标容器中进行渲染(例如，包含地图的Web页面上的<code>div</code>元素)。所有关于的map(对象)的属性可以在构造(实例对象)时配置，也可以使用<code>setter</code>方法，例如<code>setTarget()</code>。<br>下面的HTML标记可以用来创建包含地图的<code>&lt;div&gt;</code>：</p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line"><span class="tag">&lt;<span class="name">div</span> <span class="attr">id</span>=<span class="string">&quot;map&quot;</span> <span class="attr">style</span>=<span class="string">&quot;width: 100%, height: 400px&quot;</span>&gt;</span><span class="tag">&lt;/<span class="name">div</span>&gt;</span></span><br></pre></td></tr></table></figure>
<p>下面的脚本构造了一个在<code>&lt;div&gt;</code>中渲染的地图(对象)，使用上述<code>div</code>的<code>id</code>属性作为选择器。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Map</span> <span class="keyword">from</span> <span class="string">&#x27;ol/Map.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> map = <span class="keyword">new</span> <span class="title class_">Map</span>(&#123;<span class="attr">target</span>: <span class="string">&#x27;map&#x27;</span>&#125;);</span><br></pre></td></tr></table></figure>
<h3 id="View"><a href="#View" class="headerlink" title="View"></a>View</h3><p>Map的实例对象不能控制地图的中心(<code>center</code>)、缩放级别(<code>zoom</code>)和投影(<code>projection</code>)等属性。相反，这些是<code>ol/View</code>实例对象的属性。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">View</span> <span class="keyword">from</span> <span class="string">&#x27;ol/View.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line">map.<span class="title function_">setView</span>(<span class="keyword">new</span> <span class="title class_">View</span>(&#123;</span><br><span class="line">  <span class="attr">center</span>: [<span class="number">0</span>, <span class="number">0</span>],</span><br><span class="line">  <span class="attr">zoom</span>: <span class="number">2</span>,</span><br><span class="line">&#125;));</span><br></pre></td></tr></table></figure>
<p>地图视图(<code>View</code>)也有投影(<code>projection</code>属性)。投影决定了中心(<code>center</code>属性)的坐标系和地图分辨率计算的单位。如果未指定(如上面的代码块所示)，则默认投影为<strong>球面墨卡托</strong>(<code>EPSG:3857</code>)，并使用<strong>米</strong>作为地图的单位。<br>缩放(<code>zoom</code>)选项是指定地图分辨率的便捷方法。可用的缩放级别由<code>maxZoom</code>(默认设置为28)、<code>zoomFactor</code>(默认设置为2)<code>和maxResolution</code>(默认设置为投影的有效范围适合256x256像素的切片)确定。从缩放级别0开始，分辨率为每个像素的<code>maxResolution</code>单位，通过将前一个缩放级别的分辨率除以<code>zoomFactor</code>来计算后续的缩放级别，直到缩放级别达到<code>maxZoom</code>。</p>
<h3 id="Source"><a href="#Source" class="headerlink" title="Source"></a>Source</h3><p>为了获取一个图层的远程数据，OpenLayers使用<code>ol/source/Source</code>子类，它们可用于免费和商业地图切片服务，如OpenStreetMap或Bing，OGC源，如WMS或WMTS，以及GeoJSON或KML格式的矢量数据。</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="variable constant_">OSM</span> <span class="keyword">from</span> <span class="string">&#x27;ol/source/OSM.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> source = <span class="title function_">OSM</span>();</span><br></pre></td></tr></table></figure>
<h3 id="Layer"><a href="#Layer" class="headerlink" title="Layer"></a>Layer</h3><p>一个图层是某个来源的数据的可视化表示。OpenLayers有<strong>4</strong>种基本类型的层:</p>
<ul>
<li><code>ol/layer/Tile</code>：渲染在网格(grids)中提供的平铺的图像(tiled images)数据源，这些网格按特定分辨率的缩放级别进行组织。</li>
<li><code>ol/layer/Image</code>：渲染以任意范围和分辨率提供地图图像的数据源。</li>
<li><code>ol/layer/Vector</code>：在客户端渲染矢量数据。</li>
<li><code>ol/layer/VectorTile</code>：渲染以矢量切片形式提供的数据。</li>
</ul>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">TileLayer</span> <span class="keyword">from</span> <span class="string">&#x27;ol/layer/Tile.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="comment">// ...</span></span><br><span class="line"><span class="keyword">const</span> layer = <span class="keyword">new</span> <span class="title class_">TileLayer</span>(&#123;<span class="attr">source</span>: source&#125;);</span><br><span class="line">map.<span class="title function_">addLayer</span>(layer);</span><br></pre></td></tr></table></figure>
<h3 id="将上述概念放一起-举例"><a href="#将上述概念放一起-举例" class="headerlink" title="将上述概念放一起(举例)"></a>将上述概念放一起(举例)</h3><p>上面的代码块可以组合到一个脚本中，该脚本可以使用单个切片图层来渲染地图：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Map</span> <span class="keyword">from</span> <span class="string">&#x27;ol/Map.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">View</span> <span class="keyword">from</span> <span class="string">&#x27;ol/View.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="variable constant_">OSM</span> <span class="keyword">from</span> <span class="string">&#x27;ol/source/OSM.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">TileLayer</span> <span class="keyword">from</span> <span class="string">&#x27;ol/layer/Tile.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">new</span> <span class="title class_">Map</span>(&#123;</span><br><span class="line">  <span class="attr">layers</span>: [</span><br><span class="line">    <span class="keyword">new</span> <span class="title class_">TileLayer</span>(&#123;<span class="attr">source</span>: <span class="keyword">new</span> <span class="title function_">OSM</span>()&#125;),</span><br><span class="line">  ],</span><br><span class="line">  <span class="attr">view</span>: <span class="keyword">new</span> <span class="title class_">View</span>(&#123;</span><br><span class="line">    <span class="attr">center</span>: [<span class="number">0</span>, <span class="number">0</span>],</span><br><span class="line">    <span class="attr">zoom</span>: <span class="number">2</span>,</span><br><span class="line">  &#125;),</span><br><span class="line">  <span class="attr">target</span>: <span class="string">&#x27;map&#x27;</span>,</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<h2 id="关于Openlayers的一些背景知识"><a href="#关于Openlayers的一些背景知识" class="headerlink" title="关于Openlayers的一些背景知识"></a>关于Openlayers的一些背景知识</h2><h3 id="概述"><a href="#概述" class="headerlink" title="概述"></a>概述</h3><p>OpenLayers是一个模块化、高性能、功能丰富的库，用于显示地图和地理空间数据，并且可以与其进行交互。<br>该库内置支持广泛的商业和免费的图像和矢量切片数据源，以及最流行的开放和专有矢量数据格式。有了OpenLayers地图投影的支持，数据可以放置在任何投影中。</p>
<h3 id="公共API"><a href="#公共API" class="headerlink" title="公共API"></a>公共API</h3><p>OpenLayers以<a target="_blank" rel="noopener" href="https://www.npmjs.com/package/ol">ol npm package</a>的形式提供，它提供了官方支持的<a target="_blank" rel="noopener" href="https://openlayers.org/en/latest/apidoc/">API</a>的所有模块。</p>
<h3 id="浏览器支持"><a href="#浏览器支持" class="headerlink" title="浏览器支持"></a>浏览器支持</h3><p>OpenLayers可以在所有现代浏览器上运行(全球使用率超过1%)，包括Chrome、Firefox、Safari和Edge。对于较旧的浏览器，可能需要添加<a target="_blank" rel="noopener" href="https://polyfill.io/v3/">polyfills</a>。<br>该库适用于桌面、笔记本电脑和移动设备，并支持指针和触摸交互。</p>
<h3 id="模块和命名约定"><a href="#模块和命名约定" class="headerlink" title="模块和命名约定"></a>模块和命名约定</h3><p>采用<code>CamelCase</code>形式命名的OpenLayers模块提供类作为默认导出，并且可能包含额外的常量或函数作为命名导出：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Map</span> <span class="keyword">from</span> <span class="string">&#x27;ol/Map.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">View</span> <span class="keyword">from</span> <span class="string">&#x27;ol/View.js&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p>在包的子目录中提供了按其父级分组的类层次结构，例如<code>layer/</code>。<br>为方便起见，这些也可作为命名导出使用，例如</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123;<span class="title class_">Map</span>, <span class="title class_">View</span>&#125; <span class="keyword">from</span> <span class="string">&#x27;ol&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123;<span class="title class_">Tile</span>, <span class="title class_">Vector</span>&#125; <span class="keyword">from</span> <span class="string">&#x27;ol/layer.js&#x27;</span>;</span><br></pre></td></tr></table></figure>
<p>除了这些重新导出的类之外，具有小写名称的模块还提供了常量或函数作为命名导出：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> &#123;getUid&#125; <span class="keyword">from</span> <span class="string">&#x27;ol&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123;fromLonLat&#125; <span class="keyword">from</span> <span class="string">&#x27;ol/proj.js&#x27;</span>;</span><br></pre></td></tr></table></figure>
<h2 id="栅格数据重投影"><a href="#栅格数据重投影" class="headerlink" title="栅格数据重投影"></a>栅格数据重投影</h2><p>OpenLayers能够在不同的坐标系统中显示来自WMS、WMTS、静态影像和许多其他来源的栅格数据。影像投影转换会直接在Web浏览器中进行。并且地图视图(view)可以在任何<code>Proj4js</code>支持的坐标参考系统中展示，以前不兼容的图层现在也可以组合和叠加。</p>
<h3 id="用法"><a href="#用法" class="headerlink" title="用法"></a>用法</h3><p>API的使用非常简单，只需在<code>ol/View</code>上指定适当的投影（例如使用<a target="_blank" rel="noopener" href="https://epsg.io/">EPSG</a>代码）：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> <span class="title class_">Map</span> <span class="keyword">from</span> <span class="string">&#x27;ol/Map.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">TileLayer</span> <span class="keyword">from</span> <span class="string">&#x27;ol/layer/Tile.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">TileWMS</span> <span class="keyword">from</span> <span class="string">&#x27;ol/source/TileWMS.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">View</span> <span class="keyword">from</span> <span class="string">&#x27;ol/View.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> map = <span class="keyword">new</span> <span class="title class_">Map</span>(&#123;</span><br><span class="line">  <span class="attr">target</span>: <span class="string">&#x27;map&#x27;</span>,</span><br><span class="line">  <span class="attr">view</span>: <span class="keyword">new</span> <span class="title class_">View</span>(&#123;</span><br><span class="line">    <span class="attr">projection</span>: <span class="string">&#x27;EPSG:3857&#x27;</span>, <span class="comment">// here is the view projection</span></span><br><span class="line">    <span class="attr">center</span>: [<span class="number">0</span>, <span class="number">0</span>],</span><br><span class="line">    <span class="attr">zoom</span>: <span class="number">2</span>,</span><br><span class="line">  &#125;),</span><br><span class="line">  <span class="attr">layers</span>: [</span><br><span class="line">    <span class="keyword">new</span> <span class="title class_">TileLayer</span>(&#123;</span><br><span class="line">      <span class="attr">source</span>: <span class="keyword">new</span> <span class="title class_">TileWMS</span>(&#123;</span><br><span class="line">        <span class="attr">projection</span>: <span class="string">&#x27;EPSG:4326&#x27;</span>, <span class="comment">// here is the source projection</span></span><br><span class="line">        <span class="attr">url</span>: <span class="string">&#x27;https://ahocevar.com/geoserver/wms&#x27;</span>,</span><br><span class="line">        <span class="attr">params</span>: &#123;</span><br><span class="line">          <span class="string">&#x27;LAYERS&#x27;</span>: <span class="string">&#x27;ne:NE1_HR_LC_SR_W_DR&#x27;</span>,</span><br><span class="line">        &#125;,</span><br><span class="line">      &#125;),</span><br><span class="line">    &#125;),</span><br><span class="line">  ],</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>
<p>如果一个数据源(基于<code>ol/source/TileImage</code>或<code>ol/source/Image</code>)的投影不同于当前<code>ol/View</code>的投影，底层则会自动重新投影。</p>
<h3 id="例子"><a href="#例子" class="headerlink" title="例子"></a>例子</h3><ul>
<li><a href="/posts/9a4765e5/">栅格数据重新投影的例子</a></li>
<li><a href="/posts/71eddc3f/">OpenStreetMap转WGS84重投影</a></li>
<li><a href="/posts/1fbf004a/">使用EPSG.io数据库搜索进行重新投影</a></li>
<li><a href="/posts/4e1a3b55/">影像的重投影</a></li>
</ul>
<h3 id="自定义投影"><a href="#自定义投影" class="headerlink" title="自定义投影"></a>自定义投影</h3><p>使用自定义投影的最简单方法是将<a target="_blank" rel="noopener" href="http://proj4js.org/">Proj4js</a>库添加到项目中，然后使用proj4定义字符串来定义投影。输入以下命令安装：</p>
<figure class="highlight plaintext"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">npm install proj4</span><br></pre></td></tr></table></figure>
<p>下面的例子将展示<a target="_blank" rel="noopener" href="https://epsg.io/27700">British National Grid</a>坐标系的定义：</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br></pre></td><td class="code"><pre><span class="line"><span class="keyword">import</span> proj4 <span class="keyword">from</span> <span class="string">&#x27;proj4&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123;get <span class="keyword">as</span> getProjection&#125; <span class="keyword">from</span> <span class="string">&#x27;ol/proj.js&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> &#123;register&#125; <span class="keyword">from</span> <span class="string">&#x27;ol/proj/proj4.js&#x27;</span>;</span><br><span class="line"></span><br><span class="line">proj4.<span class="title function_">defs</span>(<span class="string">&#x27;EPSG:27700&#x27;</span>, <span class="string">&#x27;+proj=tmerc +lat_0=49 +lon_0=-2 +k=0.9996012717 &#x27;</span> +</span><br><span class="line">    <span class="string">&#x27;+x_0=400000 +y_0=-100000 +ellps=airy &#x27;</span> +</span><br><span class="line">    <span class="string">&#x27;+towgs84=446.448,-125.157,542.06,0.15,0.247,0.842,-20.489 &#x27;</span> +</span><br><span class="line">    <span class="string">&#x27;+units=m +no_defs&#x27;</span>);</span><br><span class="line"><span class="title function_">register</span>(proj4);</span><br><span class="line"><span class="keyword">const</span> proj27700 = <span class="title function_">getProjection</span>(<span class="string">&#x27;EPSG:27700&#x27;</span>);</span><br><span class="line">proj27700.<span class="title function_">setExtent</span>([<span class="number">0</span>, <span class="number">0</span>, <span class="number">700000</span>, <span class="number">1300000</span>]);</span><br></pre></td></tr></table></figure>
<h3 id="地图视图-View-投影的更改"><a href="#地图视图-View-投影的更改" class="headerlink" title="地图视图(View)投影的更改"></a>地图视图(View)投影的更改</h3><p>要切换用于显示地图的投影，你必须在<code>ol/Map</code>上配置一个新的<code>ol/View</code>，并配置新的投影:</p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line">map.<span class="title function_">setView</span>(<span class="keyword">new</span> <span class="title class_">View</span>(&#123;</span><br><span class="line">  <span class="attr">projection</span>: <span class="string">&#x27;EPSG:27700&#x27;</span>,</span><br><span class="line">  <span class="attr">center</span>: [<span class="number">400000</span>, <span class="number">650000</span>],</span><br><span class="line">  <span class="attr">zoom</span>: <span class="number">4</span>,</span><br><span class="line">&#125;));</span><br></pre></td></tr></table></figure>
<h3 id="切片格网和范围-TileGrid-and-Extents"><a href="#切片格网和范围-TileGrid-and-Extents" class="headerlink" title="切片格网和范围(TileGrid and Extents)"></a>切片格网和范围(TileGrid and Extents)</h3><p>当需要重新投影时，在底层新的地图切片(即在目标投影中的切片)会被来自原始数据源的切片所创建，默认情况下，重新投影的地图切片的<code>TileGrid</code>将默认使用<code>ol/tilegrid</code>的<code>getForProjection(Projection)</code>进行构建。投影应该定义一个范围(即<code>extent</code>，见上文中自定义投影这一小节)，这样才能正常工作。<br>或者，可以手动构建自定义目标投影的<code>TileGrid</code>，并使用<code>ol/source/TileImage</code>的<code>setTileGridForProjection(projection，tileggrid)</code>方法在数据源实例上进行设置。然后，在重新投影需要指定投影时将会使用手动构建的<code>TileGrid</code>而不是创建的默认<code>TileGrid</code>。在某些情况下，这可用于优化性能(通过调整切片大小)或视觉质量(通过指定分辨率)。</p>
<h3 id="工作原理"><a href="#工作原理" class="headerlink" title="工作原理"></a>工作原理</h3><p>重投影的过程基于三角形—即目标栅格被分成有限数量的三角形，其中的顶点使用<code>ol/proj</code>功能进行转换(通常使用<a target="_blank" rel="noopener" href="http://proj4js.org/">proj4js</a>来定义自定义转换)，而三角形内部像素的重新投影近似于仿射变换(affine transformation，借助canvas使用硬件加速进行渲染)：<br><img src= "/img/friend_404.gif" data-lazy-src="https://openlayers.org/doc/tutorials/raster-reprojection-resources/how-it-works.jpg"><br>通过这种方式，我们可以用相对较少的实际转换计算，在几乎任何硬件上支持来自proj4js(甚至是自定义转换函数)的各种投影(具有Canvas 2D支持)。<br>但是，重投影的精度受到三角形数量的限制。<br>重投影过程保持了原栅格数据(如png或gif)的透明度，重投影产生的间隙和无数据像素会自动变透明。</p>
<h3 id="动态三角测量-Dynamic-triangulation"><a href="#动态三角测量-Dynamic-triangulation" class="headerlink" title="动态三角测量(Dynamic triangulation)"></a>动态三角测量(Dynamic triangulation)</h3><p>上面的示例图片有一个明显的错误(特别是在边缘)，当原始图像(左图，EPSG: 27700)仅用有限数量的三角形(右图，EPSG: 3857)进行变换时。通过增加所使用的三角形的数量可以使误差最小化。<br>由于某些变换需要更详细的三角测量网络，因此动态三角测量过程会自动测量重投影误差并迭代细分以满足特定的误差阈值：<br><img src= "/img/friend_404.gif" data-lazy-src="https://openlayers.org/doc/tutorials/raster-reprojection-resources/iterative-triangulation.png"><br>为了调试，可以通过<code>ol.source.TileImage</code>下的<code>setRenderReprojectionEdges(true)</code>方法来启用重投影边缘的渲染。</p>
<h3 id="进一步地理解"><a href="#进一步地理解" class="headerlink" title="进一步地理解"></a>进一步地理解</h3><h4 id="三角测量精度阈值-Triangulation-precision-threshold"><a href="#三角测量精度阈值-Triangulation-precision-threshold" class="headerlink" title="三角测量精度阈值(Triangulation precision threshold)"></a>三角测量精度阈值(Triangulation precision threshold)</h4><p>上述默认的三角测量误差阈值(以像素为单位)由<code>ERROR_THRESHOLD</code>(0.5像素)给出，如果需要为不同的数据源定义不同的阈值，则可以在构造切片图像数据源时配置<code>reprojectionErrorThreshold</code>选项。</p>
<h4 id="按范围限制重新投影地图的可见性-Limiting-visibility-of-reprojected-map-by-extent"><a href="#按范围限制重新投影地图的可见性-Limiting-visibility-of-reprojected-map-by-extent" class="headerlink" title="按范围限制重新投影地图的可见性(Limiting visibility of reprojected map by extent)"></a>按范围限制重新投影地图的可见性(Limiting visibility of reprojected map by extent)</h4><p>重投影算法采用的时逆变换(inverse transformation，从地图视图投影到数据投影)。对于某些坐标系，这可能导致源数据在地图上“两次出现”。例如，当将瑞士地图从EPSG:21781重新投影到EPSG:3857时，它会显示两次:一次是在欧洲的适当位置，另一次是在地球另一端新西兰附近的太平洋上。<br><img src= "/img/friend_404.gif" data-lazy-src="https://openlayers.org/doc/tutorials/raster-reprojection-resources/double-occurrence.jpg"><br>虽然逆变换在数学上是没问题的，但用户并不期望在多个地方看到图层。一个可能的通用解决方案是，同时计算每个顶点的正向转换—但这将显著降低性能(特别是对于计算量大的转换)。<br>因此，一个推荐的解决方案是，在视图投影中的<code>ol.layer.Tile</code>上定义一个适当的可见范围。<a target="_blank" rel="noopener" href="https://openlayers.org/en/latest/examples/reprojection.html">重投影演示示例</a>演示了如何设置这样的限制。</p>
<h4 id="分辨率计算-Resolution-calculation"><a href="#分辨率计算-Resolution-calculation" class="headerlink" title="分辨率计算(Resolution calculation)"></a>分辨率计算(Resolution calculation)</h4><p>在切片数据加载时，需要计算一个理想的数据源的分辨率。可以使用<code>ol/reproj</code>下的<code>calculateSourceResolution(sourceProj, targetProj, targetCenter, targetResolution)</code>函数来计算理想值，以便在重新投影期间实现尽可能接近1：1的像素绘制，然后为数据源选择适当的缩放级别。<br>然而，对于整个目标缩放级别使用相同的源缩放级别通常是不现实的——不同的投影在世界的不同地方可能有明显不同的分辨率(例如EPSG:3857的极地地区 vs EPSG:4326)，对整个地图的缩放级别强制使用单一分辨率将导致一些切片被放大或缩小，可能造成需要加载大量的数据源切片。因此，分辨率绘制(resolution mapping，这里不确定怎么翻译)是为每个重新投影的切片(在切片范围的中间)单独计算的。</p>
</div><hr/><div id="post-comment"><div class="comment-head"><div class="comment-headline"><i class="fas fa-comments fa-fw"></i><span> 评论</span></div></div><div class="comment-wrap"><div><div class="vcomment" id="vcomment"></div></div></div></div></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "/img/friend_404.gif" data-lazy-src="/img/avatar.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">lovewhoilove</div><div class="author-info__description">生活原本沉闷，但跑起来就有风</div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">250</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">327</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">2</div></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">陆陆续续尝试翻译Openlayers API文档，并尝试用实例来深入学习。</div></div><div class="card-widget tzy-right-widget" id="card-wechat"><div id="flip-wrapper"><div id="flip-content"><div class="face"></div><div class="back face"></div></div></div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%9F%BA%E6%9C%AC%E6%A6%82%E5%BF%B5"><span class="toc-number">1.</span> <span class="toc-text">基本概念</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#Map"><span class="toc-number">1.1.</span> <span class="toc-text">Map</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#View"><span class="toc-number">1.2.</span> <span class="toc-text">View</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Source"><span class="toc-number">1.3.</span> <span class="toc-text">Source</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#Layer"><span class="toc-number">1.4.</span> <span class="toc-text">Layer</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B0%86%E4%B8%8A%E8%BF%B0%E6%A6%82%E5%BF%B5%E6%94%BE%E4%B8%80%E8%B5%B7-%E4%B8%BE%E4%BE%8B"><span class="toc-number">1.5.</span> <span class="toc-text">将上述概念放一起(举例)</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%85%B3%E4%BA%8EOpenlayers%E7%9A%84%E4%B8%80%E4%BA%9B%E8%83%8C%E6%99%AF%E7%9F%A5%E8%AF%86"><span class="toc-number">2.</span> <span class="toc-text">关于Openlayers的一些背景知识</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A6%82%E8%BF%B0"><span class="toc-number">2.1.</span> <span class="toc-text">概述</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%AC%E5%85%B1API"><span class="toc-number">2.2.</span> <span class="toc-text">公共API</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%B5%8F%E8%A7%88%E5%99%A8%E6%94%AF%E6%8C%81"><span class="toc-number">2.3.</span> <span class="toc-text">浏览器支持</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%A8%A1%E5%9D%97%E5%92%8C%E5%91%BD%E5%90%8D%E7%BA%A6%E5%AE%9A"><span class="toc-number">2.4.</span> <span class="toc-text">模块和命名约定</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%A0%85%E6%A0%BC%E6%95%B0%E6%8D%AE%E9%87%8D%E6%8A%95%E5%BD%B1"><span class="toc-number">3.</span> <span class="toc-text">栅格数据重投影</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%94%A8%E6%B3%95"><span class="toc-number">3.1.</span> <span class="toc-text">用法</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E4%BE%8B%E5%AD%90"><span class="toc-number">3.2.</span> <span class="toc-text">例子</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%87%AA%E5%AE%9A%E4%B9%89%E6%8A%95%E5%BD%B1"><span class="toc-number">3.3.</span> <span class="toc-text">自定义投影</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9C%B0%E5%9B%BE%E8%A7%86%E5%9B%BE-View-%E6%8A%95%E5%BD%B1%E7%9A%84%E6%9B%B4%E6%94%B9"><span class="toc-number">3.4.</span> <span class="toc-text">地图视图(View)投影的更改</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%88%87%E7%89%87%E6%A0%BC%E7%BD%91%E5%92%8C%E8%8C%83%E5%9B%B4-TileGrid-and-Extents"><span class="toc-number">3.5.</span> <span class="toc-text">切片格网和范围(TileGrid and Extents)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%B7%A5%E4%BD%9C%E5%8E%9F%E7%90%86"><span class="toc-number">3.6.</span> <span class="toc-text">工作原理</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%8A%A8%E6%80%81%E4%B8%89%E8%A7%92%E6%B5%8B%E9%87%8F-Dynamic-triangulation"><span class="toc-number">3.7.</span> <span class="toc-text">动态三角测量(Dynamic triangulation)</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%9B%E4%B8%80%E6%AD%A5%E5%9C%B0%E7%90%86%E8%A7%A3"><span class="toc-number">3.8.</span> <span class="toc-text">进一步地理解</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E4%B8%89%E8%A7%92%E6%B5%8B%E9%87%8F%E7%B2%BE%E5%BA%A6%E9%98%88%E5%80%BC-Triangulation-precision-threshold"><span class="toc-number">3.8.1.</span> <span class="toc-text">三角测量精度阈值(Triangulation precision threshold)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E6%8C%89%E8%8C%83%E5%9B%B4%E9%99%90%E5%88%B6%E9%87%8D%E6%96%B0%E6%8A%95%E5%BD%B1%E5%9C%B0%E5%9B%BE%E7%9A%84%E5%8F%AF%E8%A7%81%E6%80%A7-Limiting-visibility-of-reprojected-map-by-extent"><span class="toc-number">3.8.2.</span> <span class="toc-text">按范围限制重新投影地图的可见性(Limiting visibility of reprojected map by extent)</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%86%E8%BE%A8%E7%8E%87%E8%AE%A1%E7%AE%97-Resolution-calculation"><span class="toc-number">3.8.3.</span> <span class="toc-text">分辨率计算(Resolution calculation)</span></a></li></ol></li></ol></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item"><a class="thumbnail" href="/posts/965064e3/" title="ol/style/Style【译】"><img src= "/img/friend_404.gif" data-lazy-src="https://u-1303826255.cos.ap-nanjing.myqcloud.com/openlayers/202403232115680.png?imageMogr2/quality/75/format/webp/interlace/0" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="ol/style/Style【译】"/></a><div class="content"><a class="title" href="/posts/965064e3/" title="ol/style/Style【译】">ol/style/Style【译】</a><time datetime="2024-03-23T12:42:29.000Z" title="发表于 2024-03-23 20:42:29">2024-03-23</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/b0659e71/" title="OGC矢量切片(地理)【译】"><img src= "/img/friend_404.gif" data-lazy-src="https://u-1303826255.cos.ap-nanjing.myqcloud.com/openlayers/202304212152162.jpg?imageMogr2/quality/75/format/webp/interlace/0" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="OGC矢量切片(地理)【译】"/></a><div class="content"><a class="title" href="/posts/b0659e71/" title="OGC矢量切片(地理)【译】">OGC矢量切片(地理)【译】</a><time datetime="2024-03-10T13:51:44.000Z" title="发表于 2024-03-10 21:51:44">2024-03-10</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/posts/33015ef3/" title="谷歌地图【译】">谷歌地图【译】</a><time datetime="2024-03-10T13:21:31.000Z" title="发表于 2024-03-10 21:21:31">2024-03-10</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/38077f94/" title="悬停提示【译】"><img src= "/img/friend_404.gif" data-lazy-src="https://u-1303826255.cos.ap-nanjing.myqcloud.com/openlayers/202311162246793.jpg?imageMogr2/quality/75/format/webp/interlace/0" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="悬停提示【译】"/></a><div class="content"><a class="title" href="/posts/38077f94/" title="悬停提示【译】">悬停提示【译】</a><time datetime="2023-11-16T13:22:47.000Z" title="发表于 2023-11-16 21:22:47">2023-11-16</time></div></div><div class="aside-list-item"><a class="thumbnail" href="/posts/5c98ce7f/" title="居住地渲染【译】"><img src= "/img/friend_404.gif" data-lazy-src="https://u-1303826255.cos.ap-nanjing.myqcloud.com/openlayers/202311162246139.jpg?imageMogr2/quality/75/format/webp/interlace/0" onerror="this.onerror=null;this.src='/img/404.jpg'" alt="居住地渲染【译】"/></a><div class="content"><a class="title" href="/posts/5c98ce7f/" title="居住地渲染【译】">居住地渲染【译】</a><time datetime="2023-11-16T12:25:46.000Z" title="发表于 2023-11-16 20:25:46">2023-11-16</time></div></div></div></div><div class="card-widget card-categories"><div class="item-headline">
            <i class="fas fa-folder-open"></i>
            <span>分类</span>
            
            </div>
            <ul class="card-category-list" id="aside-cat-list">
            <li class="card-category-list-item "><a class="card-category-list-link" href="/categories/GIS%E8%B5%84%E6%BA%90/"><span class="card-category-list-name">GIS资源</span><span class="card-category-list-count">1</span></a></li><li class="card-category-list-item "><a class="card-category-list-link" href="/categories/Openlayers/"><span class="card-category-list-name">Openlayers</span><span class="card-category-list-count">249</span></a></li>
            </ul></div><div class="card-widget card-tags"><div class="item-headline"><i class="fas fa-tags"></i><span>标签</span></div><div class="card-tag-cloud"><a href="/tags/epsg4326/" style="font-size: 1.17em; color: rgb(178, 199, 185)">epsg4326<sup>2</sup></a><a href="/tags/vectortiles/" style="font-size: 1.22em; color: rgb(29, 33, 82)">vectortiles<sup>5</sup></a><a href="/tags/mapboxstyle/" style="font-size: 1.17em; color: rgb(15, 134, 104)">mapboxstyle<sup>2</sup></a><a href="/tags/ol-mapbox-style/" style="font-size: 1.17em; color: rgb(66, 61, 118)">ol-mapbox-style<sup>2</sup></a><a href="/tags/maptiler/" style="font-size: 1.42em; color: rgb(47, 53, 179)">maptiler<sup>26</sup></a><a href="/tags/grid/" style="font-size: 1.3em; color: rgb(62, 0, 171)">grid<sup>8</sup></a><a href="/tags/vector/" style="font-size: 1.45em; color: rgb(122, 141, 91)">vector<sup>79</sup></a><a href="/tags/esri/" style="font-size: 1.2em; color: rgb(80, 27, 64)">esri<sup>3</sup></a><a href="/tags/ArcGIS/" style="font-size: 1.2em; color: rgb(90, 162, 195)">ArcGIS<sup>3</sup></a><a href="/tags/REST/" style="font-size: 1.2em; color: rgb(5, 80, 21)">REST<sup>3</sup></a><a href="/tags/Feature/" style="font-size: 1.17em; color: rgb(90, 66, 38)">Feature<sup>2</sup></a><a href="/tags/Service/" style="font-size: 1.17em; color: rgb(16, 150, 98)">Service<sup>2</sup></a><a href="/tags/loading/" style="font-size: 1.3em; color: rgb(85, 148, 112)">loading<sup>8</sup></a><a href="/tags/server/" style="font-size: 1.22em; color: rgb(198, 120, 68)">server<sup>5</sup></a><a href="/tags/arcgis/" style="font-size: 1.17em; color: rgb(175, 61, 155)">arcgis<sup>2</sup></a><a href="/tags/image/" style="font-size: 1.27em; color: rgb(65, 15, 82)">image<sup>7</sup></a><a href="/tags/dynamiclayer/" style="font-size: 1.15em; color: rgb(148, 57, 199)">dynamiclayer<sup>1</sup></a><a href="/tags/cog/" style="font-size: 1.35em; color: rgb(189, 169, 52)">cog<sup>13</sup></a><a href="/tags/ndvi/" style="font-size: 1.2em; color: rgb(13, 59, 113)">ndvi<sup>3</sup></a><a href="/tags/ndwi/" style="font-size: 1.15em; color: rgb(117, 111, 93)">ndwi<sup>1</sup></a><a href="/tags/sentinel/" style="font-size: 1.15em; color: rgb(20, 97, 175)">sentinel<sup>1</sup></a><a href="/tags/geotiff/" style="font-size: 1.17em; color: rgb(185, 21, 139)">geotiff<sup>2</sup></a><a href="/tags/projection/" style="font-size: 1.35em; color: rgb(101, 81, 193)">projection<sup>13</sup></a><a href="/tags/proj4js/" style="font-size: 1.25em; color: rgb(2, 186, 14)">proj4js<sup>6</sup></a><a href="/tags/layers/" style="font-size: 1.17em; color: rgb(16, 21, 145)">layers<sup>2</sup></a><a href="/tags/openstreetmap/" style="font-size: 1.4em; color: rgb(195, 147, 183)">openstreetmap<sup>22</sup></a><a href="/tags/canvas/" style="font-size: 1.25em; color: rgb(92, 64, 189)">canvas<sup>6</sup></a><a href="/tags/simple/" style="font-size: 1.22em; color: rgb(31, 140, 103)">simple<sup>5</sup></a><a href="/tags/attribution/" style="font-size: 1.15em; color: rgb(64, 1, 66)">attribution<sup>1</sup></a><a href="/tags/animation/" style="font-size: 1.22em; color: rgb(74, 75, 74)">animation<sup>5</sup></a><a href="/tags/style/" style="font-size: 1.42em; color: rgb(191, 64, 102)">style<sup>26</sup></a><a href="/tags/icon/" style="font-size: 1.32em; color: rgb(183, 155, 162)">icon<sup>9</sup></a><a href="/tags/gif/" style="font-size: 1.15em; color: rgb(68, 124, 131)">gif<sup>1</sup></a><a href="/tags/GPX/" style="font-size: 1.15em; color: rgb(18, 194, 2)">GPX<sup>1</sup></a><a href="/tags/geojson/" style="font-size: 1.32em; color: rgb(56, 78, 58)">geojson<sup>9</sup></a><a href="/tags/tilepyramid/" style="font-size: 1.15em; color: rgb(138, 68, 144)">tilepyramid<sup>1</sup></a><a href="/tags/stac/" style="font-size: 1.17em; color: rgb(88, 193, 62)">stac<sup>2</sup></a><a href="/tags/webgl/" style="font-size: 1.38em; color: rgb(140, 94, 67)">webgl<sup>17</sup></a><a href="/tags/reprojection/" style="font-size: 1.3em; color: rgb(73, 142, 68)">reprojection<sup>8</sup></a><a href="/tags/complex-geometry/" style="font-size: 1.15em; color: rgb(29, 84, 72)">complex-geometry<sup>1</sup></a></div></div><div class="card-widget card-archives"><div class="item-headline"><i class="fas fa-archive"></i><span>时间轴</span></div><ul class="card-archive-list"><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2024/03/"><span class="card-archive-list-date">三月 2024</span><span class="card-archive-list-count">3</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/11/"><span class="card-archive-list-date">十一月 2023</span><span class="card-archive-list-count">2</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/10/"><span class="card-archive-list-date">十月 2023</span><span class="card-archive-list-count">11</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/05/"><span class="card-archive-list-date">五月 2023</span><span class="card-archive-list-count">52</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/04/"><span class="card-archive-list-date">四月 2023</span><span class="card-archive-list-count">181</span></a></li><li class="card-archive-list-item"><a class="card-archive-list-link" href="/archives/2023/01/"><span class="card-archive-list-date">一月 2023</span><span class="card-archive-list-count">1</span></a></li></ul></div><div class="card-widget card-webinfo"><div class="item-headline"><i class="fas fa-chart-line"></i><span>网站资讯</span></div><div class="webinfo"><div class="webinfo-item"><div class="item-name">文章数目 :</div><div class="item-count">250</div></div><div class="webinfo-item"><div class="item-name">已运行时间 :</div><div class="item-count" id="runtimeshow" data-publishDate="2022-12-13T16:00:00.000Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总字数 :</div><div class="item-count">177.9k</div></div><div class="webinfo-item"><div class="item-name">本站访客数 :</div><div class="item-count" id="busuanzi_value_site_uv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">本站总访问量 :</div><div class="item-count" id="busuanzi_value_site_pv"><i class="fa-solid fa-spinner fa-spin"></i></div></div><div class="webinfo-item"><div class="item-name">最后更新时间 :</div><div class="item-count" id="last-push-date" data-lastPushDate="2024-04-25T00:57:24.420Z"><i class="fa-solid fa-spinner fa-spin"></i></div></div></div></div></div></div></main><footer id="footer" style="background-image: url('/img/homepage-banner.webp')"><div id="footer-wrap"><div class="copyright">&copy;2022 - 2024 <i style="color:red" class="fa fa-heartbeat fa-beat"></i> By lovewhoilove</div><div class="footer_custom_text">生活原本沉闷，但跑起来就有风🎈</div></div></footer></div><div id="rightside"><div id="rightside-config-hide"></div><div id="rightside-config-show"><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><a class="icon-V hidden" onclick="switchNightMode()" title="浅色和深色模式转换"><svg width="25" height="25" viewBox="0 0 1024 1024"><use id="modeicon" xlink:href="#icon-moon"></use></svg></a><a id="to_comment" href="#post-comment" title="直达评论"><i class="fas fa-comments"></i></a><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button><button id="go-down" type="button" title="直达底部" onclick="btf.scrollToDest(document.body.scrollHeight, 500)"><i class="fas fa-arrow-down"></i></button></div></div><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div id="local-search-results"></div></div></div><div id="search-mask"></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><script src="/js/search/local-search.js"></script><div class="js-pjax"><script>(() => {
  const $mermaidWrap = document.querySelectorAll('#article-container .mermaid-wrap')
  if ($mermaidWrap.length) {
    window.runMermaid = () => {
      window.loadMermaid = true
      const theme = document.documentElement.getAttribute('data-theme') === 'dark' ? 'dark' : 'default'

      Array.from($mermaidWrap).forEach((item, index) => {
        const mermaidSrc = item.firstElementChild
        const mermaidThemeConfig = '%%{init:{ \'theme\':\'' + theme + '\'}}%%\n'
        const mermaidID = 'mermaid-' + index
        const mermaidDefinition = mermaidThemeConfig + mermaidSrc.textContent
        mermaid.mermaidAPI.render(mermaidID, mermaidDefinition, (svgCode) => {
          mermaidSrc.insertAdjacentHTML('afterend', svgCode)
        })
      })
    }

    const loadMermaid = () => {
      window.loadMermaid ? runMermaid() : getScript('https://cdn.jsdelivr.net/npm/mermaid/dist/mermaid.min.js').then(runMermaid)
    }

    window.pjax ? loadMermaid() : document.addEventListener('DOMContentLoaded', loadMermaid)
  }
})()</script><script>function loadValine () {
  function initValine () {
    const valine = new Valine(Object.assign({
      el: '#vcomment',
      appId: 's2D3RXeuiTBrJjXpdIo4bJuK-gzGzoHsz',
      appKey: 'e6j6L6lA50bj18TlkcZEMw0O',
      avatar: 'monsterid',
      serverURLs: '',
      emojiMaps: "",
      path: window.location.pathname,
      visitor: false
    }, {"placeholder":"畅所欲言哈😁~~"}))
  }

  if (typeof Valine === 'function') initValine() 
  else getScript('https://cdn.jsdelivr.net/npm/valine/dist/Valine.min.js').then(initValine)
}

if ('Valine' === 'Valine' || !true) {
  if (true) btf.loadComment(document.getElementById('vcomment'),loadValine)
  else setTimeout(loadValine, 0)
} else {
  function loadOtherComment () {
    loadValine()
  }
}</script></div><script src="/js/sun_moon.js"></script><script src="/js/jquery.min.js"></script><script data-pjax defer src="/js/chocolate.js"></script><script defer type="text/javascript" src="/js/sweetalert2.all.js"></script><script defer src="/js/lunar.js"></script><script defer src="/js/day.js"></script><script data-pjax defer src="/js/fishes.js"></script><canvas id="universe"></canvas><script src="/js/universe.js"></script><script defer="defer" id="fluttering_ribbon" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-fluttering-ribbon.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/activate-power-mode.min.js"></script><script>POWERMODE.colorful = true;
POWERMODE.shake = true;
POWERMODE.mobile = false;
document.body.addEventListener('input', POWERMODE);
</script><script id="click-heart" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/click-heart.min.js" async="async" mobile="false"></script><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/aplayer/dist/APlayer.min.js"></script><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/metingjs/dist/Meting.min.js"></script><script src="https://cdn.jsdelivr.net/npm/pjax/pjax.min.js"></script><script>let pjaxSelectors = ["head > title","#config-diff","#body-wrap","#rightside-config-hide","#rightside-config-show",".js-pjax"]

var pjax = new Pjax({
  elements: 'a:not([target="_blank"])',
  selectors: pjaxSelectors,
  cacheBust: false,
  analytics: false,
  scrollRestoration: false
})

document.addEventListener('pjax:send', function () {

  // removeEventListener scroll 
  window.tocScrollFn && window.removeEventListener('scroll', window.tocScrollFn)
  window.scrollCollect && window.removeEventListener('scroll', scrollCollect)

  document.getElementById('rightside').style.cssText = "opacity: ''; transform: ''"
  
  if (window.aplayers) {
    for (let i = 0; i < window.aplayers.length; i++) {
      if (!window.aplayers[i].options.fixed) {
        window.aplayers[i].destroy()
      }
    }
  }

  typeof typed === 'object' && typed.destroy()

  //reset readmode
  const $bodyClassList = document.body.classList
  $bodyClassList.contains('read-mode') && $bodyClassList.remove('read-mode')

  typeof disqusjs === 'object' && disqusjs.destroy()
})

document.addEventListener('pjax:complete', function () {
  window.refreshFn()

  document.querySelectorAll('script[data-pjax]').forEach(item => {
    const newScript = document.createElement('script')
    const content = item.text || item.textContent || item.innerHTML || ""
    Array.from(item.attributes).forEach(attr => newScript.setAttribute(attr.name, attr.value))
    newScript.appendChild(document.createTextNode(content))
    item.parentNode.replaceChild(newScript, item)
  })

  GLOBAL_CONFIG.islazyload && window.lazyLoadInstance.update()

  typeof chatBtnFn === 'function' && chatBtnFn()
  typeof panguInit === 'function' && panguInit()

  // google analytics
  typeof gtag === 'function' && gtag('config', '', {'page_path': window.location.pathname});

  // baidu analytics
  typeof _hmt === 'object' && _hmt.push(['_trackPageview',window.location.pathname]);

  typeof loadMeting === 'function' && document.getElementsByClassName('aplayer').length && loadMeting()

  // prismjs
  typeof Prism === 'object' && Prism.highlightAll()
})

document.addEventListener('pjax:error', (e) => {
  if (e.request.status === 404) {
    pjax.loadUrl('/404.html')
  }
})</script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script></div><!-- hexo injector body_end start --><div class="js-pjax"><script async="async">var arr = document.getElementsByClassName('recent-post-item');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '2s');
    arr[i].setAttribute('data-wow-delay', '1s');
    arr[i].setAttribute('data-wow-offset', '100');
    arr[i].setAttribute('data-wow-iteration', '1');
  }</script><script async="async">var arr = document.getElementsByClassName('card-widget');
for(var i = 0;i<arr.length;i++){
    arr[i].classList.add('wow');
    arr[i].classList.add('animate__zoomIn');
    arr[i].setAttribute('data-wow-duration', '');
    arr[i].setAttribute('data-wow-delay', '');
    arr[i].setAttribute('data-wow-offset', '');
    arr[i].setAttribute('data-wow-iteration', '');
  }</script></div><script defer src="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow.min.js"></script><script defer src="https://npm.elemecdn.com/hexo-butterfly-wowjs/lib/wow_init.js"></script><!-- hexo injector body_end end --></body></html>